package com.cheney.demo.controller;

import com.cheney.demo.config.RocketMqConfig;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author si.chen
 * @date 2021/7/7 17:49
 */
@RestController
@RequestMapping("/stream")
public class StreamController {

    @Autowired
    private RocketMqConfig.MySource source;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 生产-字符串
     */
    @GetMapping("send")
    public String send() {
        source.output().send(MessageBuilder.withPayload("你好 output").build());
        source.output2().send(MessageBuilder.withPayload("你好 output2").build());
        //rocketMQTemplate使用
        rocketMQTemplate.send("test-topic1", MessageBuilder.withPayload("rocketMQTemplate ==> test-topic1").build());
        return "ok";
    }


}
